var indexLoad = null;
layui.use([ 'element', 'form' ], function() {
	var element = layui.element(), form = layui.form();
	var config = {
		url : "./assetscrap/list.shtml",
		page : true,
		select : false,
		columns : [{
			text : '报废单编号',
			name : 'id',
			width : 15
		}, {
			text : '车次',
			name : 'trainNumber',
			width : 15
		}, {
			text : '申请人',
			name : 'createUserName',
			width : 10
		}, {
			text : '申请时间',
			name : 'createTime',
			width : 10,
			formatter:function(value,row,index){
				return formatterDate(value);
			}
		},{
			text : '状态',
			name : 'status',
			width : 10,
			formatter:function(value,row,index){
				if (value == "0" || value == 0) {
					return "未处理";
				} else if (value == "1" || value == 1) {
					return "报废";
				} else if (value == "2" || value == 2) {
					return "驳回";
				}
			}
		}, {
			text : '操作',
			formatter : function(value, row, index) {
				if(row.status == "0" || row.status == 0){
					return "<button class='layui-btn layui-btn-primary' onclick='assetScrapDetail(this)' title='" + index + "'>查看</button>" +
						   "<button class='layui-btn layui-btn-primary' onclick='assetScrapApprove(this)' title='" + index + "'>审批</button>";
				}else {
					return "<button class='layui-btn layui-btn-primary' onclick='assetScrapDetail(this)' title='" + index + "'>查看</button>";
				}
			},
		
			width : 10
		}],
		onBeforeLoad : function(param) {
            indexLoad = layer.load(1);
			return param;
		},
		onLoadSuccess : function (data) {
            layer.close(indexLoad);
			return data;
		},
		dataFilter : function(data) {
			return data;
		}
	};
	$("#assetScrapTable").jfTable(config);

	// 重新渲染，初始化分页。
	refreshAssetScrapList();

	// 刷新列表
	$('#assetScrapRefresh').click(function() {
		refreshAssetScrapList();
	})
	form.on('submit(formQuery)', function(data) {
		refreshAssetScrapList();
		return false;
	});
})
function refreshAssetScrapList(){
	layer.load(1);
	var query_id = $('#id').val();
	var query_status = $('#status').val();
	/*console.info(query_status);*/
	var obj = {};
	obj.id = query_id;
	obj.status = query_status;
	/*console.info(obj);*/
	$("#assetScrapTable").jfTable("reload",obj)
}
	// 查看报废详情
function assetScrapDetail(obj){
	var row = $("#assetScrapTable").jfTable("getRow",obj.title);
	var rowJson = JSON.stringify(row);
	layer.open({
		type : 2,
		move : false,
		title : '首页 / 报废单管理 / 查看',
        area : [ window.innerWidth-150+"px", window.innerHeight-100+"px" ],
		content : './assetscrap/getAssetScrapDetail.shtml?rowJson='+obj.title+'&id='+row.id
		/*maxmin : true,
		fixed: false*/
	});
}
//报废审批
function assetScrapApprove(obj){
	var row = $("#assetScrapTable").jfTable("getRow",obj.title);
	var rowJson = JSON.stringify(row);
	layer.open({
		type : 2,
		move : false,
		title : '首页 / 报废单管理 / 审批',
        area : [ window.innerWidth-150+"px", window.innerHeight-100+"px" ],
		content : './assetscrap/getAssetScrapApprove.shtml?rowJson='+obj.title+'&id='+row.id
		/*maxmin : true,
		fixed: false*/
	});
}